package logic

import (
	"context"
	"encoding/json"
	"weee/models"

	"weee/orderrpc/internal/svc"
	"weee/orderrpc/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsShowLogic {
	return &GoodsShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GoodsShow todo: 商品展示
func (l *GoodsShowLogic) GoodsShow(in *orderrpc.GoodsShowRequest) (*orderrpc.GoodsShowResponse, error) {
	// todo: add your logic here and delete this line
	GoodsAll, err := models.GetGoodsAll()
	if err != nil {
		return &orderrpc.GoodsShowResponse{
			Code: 400,
			Msg:  "查询失败",
		}, nil
	}
	goods, _ := json.Marshal(GoodsAll)
	return &orderrpc.GoodsShowResponse{
		Code: 200,
		Msg:  "查询成功",
		Data: string(goods),
	}, nil
}
